// 按需引入方式
// import echarts from "@/views/package/echarts/components/BaseEcharts/utils/echarts";

export function getOptions(paramsData) {
  console.log("paramsData", paramsData);
  const colorList = ["#66d6fb", "#d19a42"];
  const defaultFontColor = "#fff";
  const requestData = paramsData.filter((item) => item.时间 !== "日分析");
  const xData = requestData.map((item) => item.时间);
  xData.sort((a, b) => new Date(a).getTime() - new Date(b).getTime());
  console.log("xData", xData);
  const dataList = [];
  const legendNameList = requestData[0].checkArr;
 
  const unitName = requestData[0].机组名称;
  console.log("legend", legendNameList);

  legendNameList.forEach((key, index) => {
    const obj = {
      name: unitName + "-" + key,
      data: [],
      color: colorList[index % colorList.length],
    };
    xData.forEach((time) => {
      const item = requestData.find((i) => i.时间 == time);
      if (item) {
        obj.data.push(item[key]);
      }
    });
    dataList.push(obj);
  });
  console.log("dataList", dataList);

  // const dataList = [
  //   {
  //     name: "上游水位",
  //     // yAxisName: "上游水位(m)",
  //     data: [386, 11, 13, 11, 12, 12, 9],
  //     color: colorList[0],
  //   },

  //   {
  //     name: "下游水位",
  //     // yAxisName: "下游水位(m)",
  //     data: [1, -2, 2, 5, 3, 2, 0],
  //     color: colorList[1],
  //   },
  // ];

  const series = dataList.map((item) => {
    return {
      name: item.name,
      type: "line",
      data: item.data,
      smooth: 0.6,
      lineStyle: {
        color: item.color,
      },
      // showSymbol: true, //是否默认展示圆点
      // symbolSize: 10, //设定实心点的大小
      itemStyle: {
        normal: {
          color: item.color, //改变折线点的颜色
        },
      },
      markPoint: {
        data: [{ type: "max", name: "Max" }],
      },
    };
  });

  const option = {
    tooltip: {
      trigger: "axis",
      backgroundColor: "#283c7e",
      borderColor: "#283c7e",
      textStyle: {
        color: "#fff",
      },
    },
    legend: {
      show: true,
      type: 'scroll', 
      data: dataList.map((item) => {
        return {
          name: item.name,
          textStyle: { color: item.color },
        };
      }),
    },
    grid: [
      {
        top: 70,
        bottom: 101,
        left: 50,
        right: 50,
      },
    ],
    // toolbox: {
    //   show: true,
    //   feature: {
    //     dataZoom: {
    //       yAxisIndex: "none",
    //     },
    //     dataView: { readOnly: false },
    //     magicType: { type: ["line", "bar"] },
    //     restore: {},
    //     saveAsImage: {},
    //   },
    // },
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: xData,
      axisLine: {
        show: true,
        lineStyle: {
          color: dataList[0].color,
          width: 2,
        },
      },
      axisLabel: {
        //y轴文字的配置
        textStyle: {
          color: defaultFontColor,
          margin: 15,
        },
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: "#ccc",
          type: "dashed",
          dashOffset: "20",
          opacity: 0.3,
        },
      },
    },

    yAxis: {
      // name: dataList[0].yAxisName,
      type: "value",
      position: "left",
      offset: "0",
      axisTick: {
        show: true,
      },
      alignTicks: true, // 开启该配置项自动对齐刻度
      axisLine: {
        show: true,
        lineStyle: {
          color: dataList[0].color,
          width: 2,
        },
      },
      axisLabel: {
        //y轴文字的配置
        textStyle: {
          color: defaultFontColor,
          margin: 15,
        },
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: "#ccc",
          type: "dashed",
          dashOffset: "20",
          opacity: 0.3,
        },
      },
    },

    series,
  };

  return option;
}
